/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package slisfx.devices;

import java.util.ArrayList;
import slisfx.Globals;
import slisfx.user.Userbase;
import slisfx.user.Users;

/**
 *
 * @author Rebecca
 */
public class Devicebase implements Globals{
    
    	private ArrayList<Device> deviceKeeper = new ArrayList<Device>();
	private static final Devicebase deviceBaseFinal = new Devicebase();
        
        public static Devicebase getDevicebase(){
		return deviceBaseFinal;
	}
        
        public void add_device(Device d){
            deviceKeeper.add(d);
        }
        
        public void remove_device(String dName){
            for(Device d: deviceKeeper){
                if(d.getDeviceName().equalsIgnoreCase(dName)){
                    deviceKeeper.remove(d);
                }
            }
        }
        
        	public int check_device_status(String dName) {
		for(Device d: deviceKeeper){
			if(d.getDeviceName().compareToIgnoreCase(dName) == 0){
                            if(d.getDeviceStatus()){
                                return DEVICE_IS_ON;
                            }
                            else{
                                return DEVICE_IS_OFF;
                            }
			}
			else{
                            return DEVICE_DOES_NOT_EXIST;
			}
		}
		return NO_CURRENT_DEVICES;
	}
        
        public String toXML(){	
		String xmlString = new String();
		for(Device d: deviceKeeper){
			xmlString += d.toXML();
		}
		return xmlString; 	
	}
    
}
